const { UUIDV4, UUID, STRING, TEXT, JSON, TINYINT, Model } = require('sequelize');
const db = require('../../helpers/db');
const AfterSaleRecords = require('./after-sale-records');

class AfterSale extends Model {}

AfterSale.init(
    {
        id: {
            type: UUID,
            defaultValue: UUIDV4,
            primaryKey: true,
            comment: '商品详情ID'
        },
        no: {
            type: STRING(24),
            comment: '售后编号'
        },
        orderItem: {
            type: UUID,
            unique: true,
            comment: '外键，订单项ID',
            field: 'order_item'
        },
        user: {
            type: UUID,
            unique: true,
            comment: '外键，用户ID'
        },
        type: {
            type: TINYINT(1),
            defaultValue: 0,
            comment: '售后类型，0换货，1退款退货，2仅退款'
        },
        imageList: {
            type: STRING(512),
            comment: '图片列表',
            allowNull: false,
            field: 'image_list'
        },
        reason: {
            type: TEXT,
            comment: '售后原因',
            allowNull: false
        },
        remark: {
            type: STRING(32),
            comment: '备注'
        },
        status: {
            type: TINYINT(1),
            defaultValue: 0,
            comment: '售后状态，0未完成，1已完成'
        },
        logisticsCompany: {
            type: STRING(128),
            comment: '物流公司',
            field: 'logistics_company'
        },
        logisticsNumber: {
            type: STRING,
            comment: '物流单号',
            field: 'logistics_number'
        }
    },
    {
        tableName: 'after_sale',
        underscored: true,
        sequelize: db
    }
);

AfterSale.hasOne(AfterSaleRecords, {
    foreignKey: 'afterSale'
});

module.exports = AfterSale;
